package com.designoutput.ui.options.components
{
	import com.designoutput.enum.ToolType;
	import com.designoutput.icon.FontBoldIcon;
	import com.designoutput.icon.FontItalicIcon;
	import com.designoutput.icon.FontShadowIcon;
	import com.designoutput.icon.FontUnderlineIcon;
	import com.designoutput.ui.controls.ToolButton;
	import com.designoutput.ui.options.TextOption;
	
	import flash.display.Sprite;
	import flash.events.MouseEvent;
	
	public class BaseFotmatGroup extends Sprite
	{
		private var baseOption:TextOption;
		
		private var bold:ToolButton;
		private var italic:ToolButton;
		private var underline:ToolButton;
		private var shadow:ToolButton;
		
		private var _fontBold:Boolean = false;
		private var _fontItalic:Boolean = false;
		private var _fontUnderline:Boolean = false;
		private var _fontShadow:Boolean = false;
		
		public function BaseFotmatGroup(baseOption:TextOption)
		{
			this.baseOption = baseOption;
			this.build();
		}

		private function build():void{
			bold = new ToolButton(ToolType.FontBold,new FontBoldIcon(0,0) ,2,2);
			bold.addEventListener(MouseEvent.MOUSE_DOWN, this.ToolMouseDown);
			bold.x = 0;
			bold.y = 10;
			this.addChild(bold);
			
			italic = new ToolButton(ToolType.FontItalic,new FontItalicIcon(0,0),2,2);
			italic.addEventListener(MouseEvent.MOUSE_DOWN, this.ToolMouseDown);
			italic.x = 30;
			italic.y = 10;
			this.addChild(italic);
			
			underline = new ToolButton(ToolType.FontUnderline,new FontUnderlineIcon(0,0),2,2);
			underline.addEventListener(MouseEvent.MOUSE_DOWN, this.ToolMouseDown);
			underline.x = 60;
			underline.y = 10;
			this.addChild(underline);
			
			shadow = new ToolButton(ToolType.FontShadow,new FontShadowIcon(0,0),5,5);
			shadow.addEventListener(MouseEvent.MOUSE_DOWN, this.ToolMouseDown);
			shadow.x = 90;
			shadow.y = 10;
			this.addChild(shadow);
		}
		
		
		public function get fontShadow():Boolean
		{
			return _fontShadow;
		}
		
		public function set fontShadow(value:Boolean):void
		{
			_fontShadow = value;
			if(value){
				if(!shadow.isMarked()){
					shadow.Mark(value);
				}
			}else{
				if(shadow.isMarked()){
					shadow.Mark(value);
				}
			}
		}
		
		public function get fontUnderline():Boolean
		{
			return _fontUnderline;
		}
		
		public function set fontUnderline(value:Boolean):void
		{
			_fontUnderline = value;
			if(value){
				if(!underline.isMarked()){
					underline.Mark(value);
				}
			}else{
				if(underline.isMarked()){
					underline.Mark(value);
				}
			}
		}
		
		public function get fontItalic():Boolean
		{
			return _fontItalic;
		}
		
		public function set fontItalic(value:Boolean):void
		{
			_fontItalic = value;
			if(value){
				if(!italic.isMarked()){
					italic.Mark(value);
				}
			}else{
				if(italic.isMarked()){
					italic.Mark(value);
				}
			}
		}
		
		public function get fontBold():Boolean
		{
			return _fontBold;
		}
		
		public function set fontBold(value:Boolean):void
		{
			_fontBold = value;
			if(value){
				if(!bold.isMarked()){
					bold.Mark(value);
				}
			}else{
				if(bold.isMarked()){
					bold.Mark(value);
				}
			}
		}
		
		private function ToolMouseDown(evt:MouseEvent):void{
			var toolButton:ToolButton = evt.currentTarget as ToolButton;
			switch(toolButton.type){
				case ToolType.FontBold:
					this.baseOption.bold = !bold.isMarked();
					this.baseOption.updateTextElemet();
					bold.Mark(!bold.isMarked());
					break;
				case ToolType.FontItalic:
					this.baseOption.italic = !italic.isMarked();
					this.baseOption.updateTextElemet();
					italic.Mark(!italic.isMarked());
					break;
				case ToolType.FontUnderline:
					this.baseOption.underline = !underline.isMarked();
					this.baseOption.updateTextElemet();
					underline.Mark(!underline.isMarked());
					break;
				case ToolType.FontShadow:
					this.baseOption.shadow = !shadow.isMarked();
					this.baseOption.updateTextElemet();
					shadow.Mark(!shadow.isMarked());
					break;
				default:
					break;
			}
		}
		
	}
}